package com.slt.jvm.mashibing.c3_jmm;//package com.example.jvmstudy.mashibing.jvm.c3_jmm;


import com.slt.jvm.mashibing.javaAgent.ObjectSizeAgent;

/**
 * 对象大小问题
 */
public class T03_SizeOfAnObject {
    public static void main(String[] args) {
        System.out.println(ObjectSizeAgent.sizeOf(new Object())); // 8 +4 +4（padding） = 16
        System.out.println(ObjectSizeAgent.sizeOf(new int[] {}));// 8 + 4 +4 = 16
        System.out.println(ObjectSizeAgent.sizeOf(new P()));//32
    }

    //一个Object占多少个字节
    // -XX:+UseCompressedClassPointers ： 压缩classpointer
    // -XX:+UseCompressedOops     Oops = ordinary object pointers 压缩的是普通引用指针
    private static class P {
                        //8 _markword
                        //4 _class pointer
        int id;         //4
        String name;    //4
        int age;        //4

        byte b1;        //1
        byte b2;        //1

        Object o;       //4
        byte b3;        //1

    }
}
